{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us now define the initial distribution which represents the state of the system at k=0.\n",
    "Our system is composed of two states and we can model the initial distribution as a vector with two elements, the first element of the vector represents the probability of staying in the state s0 and the second element the probability of staying in state s1. Let’s suppose that we start from s0, the vector v representing the initial distribution will have this form:\n",
    "v=(1,0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculating the probability of being in a specific state after k iterations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "v: [[1. 0.]]\n",
      "v_1: [[0.9 0.1]]\n",
      "v_5: [[0.83504 0.16496]]\n",
      "v_25: [[0.83333333 0.16666667]]\n",
      "v_50: [[0.83333333 0.16666667]]\n",
      "v_100: [[0.83333333 0.16666667]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "#Declare the initial distribution\n",
    "v = np.array([[1.0, 0.0]])\n",
    "\n",
    "#Declare the Transition Matrix T(this is the same matrix used as in the file'Calculating Transition Probabilities')\n",
    "T = np.array([[0.90, 0.10],\n",
    "              [0.50, 0.50]])\n",
    "\n",
    "#Obtain T after 5 steps\n",
    "T_5 = np.linalg.matrix_power(T, 5)\n",
    "\n",
    "#Obtain T after 25 steps\n",
    "T_25 = np.linalg.matrix_power(T, 25)\n",
    "\n",
    "#Obtain T after 50 steps\n",
    "T_50 = np.linalg.matrix_power(T, 50)\n",
    "\n",
    "#Obtain T after 100 steps\n",
    "T_100 = np.linalg.matrix_power(T, 100)\n",
    "\n",
    "#Printing the initial distribution\n",
    "print(\"v: \" + str(v))\n",
    "print(\"v_1: \" + str(np.dot(v,T)))\n",
    "print(\"v_5: \" + str(np.dot(v,T_5)))\n",
    "print(\"v_25: \" + str(np.dot(v,T_25)))\n",
    "print(\"v_50: \" + str(np.dot(v,T_50)))\n",
    "print(\"v_100: \" + str(np.dot(v,T_100)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result after 50 and 100 iterations are the same and v_50 is equal to v_100 no matter which starting distribution we have. The chain converged to equilibrium meaning that as the time progresses it forgets about the starting distribution."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
